package jflowmap.model.ontology.calculation;

import java.util.Map;

import jflowmap.model.ontology.Context;
import jflowmap.model.ontology.Value;
import jflowmap.model.ontology.calculation.expression.Expression;
import jflowmap.model.ontology.calculation.expression.VariableMissingException;

public class Calculation {
	
	public Calculation use (Expression expression) {
		this.expression = expression;
		return this;
	}
	
	public Value calculate(Context context, Map<String, Variable> vars) throws VariableMissingException {
		this.vars = vars;
		if (expression == null) {
			throw new IllegalStateException("Define an expression for the calculation!");
		}
		return context.create(expression.value(vars));
	}
	
	private Map<String, Variable> vars;
	private Expression expression;

}
